"""author: wangxin
   data: 2021/12/8
   project: cjh.py
"""
# 查找文件中最长的行，输出长度 考虑文件比较大 考虑代码精简
import string
import random


def func(a):
    m = 0
    for i in a:
        if len(i) > m:
            m = len(i)
            yield m, i


with open('bigdata.txt', 'w+', encoding="utf-8")as f:
    for i in range(1000):
        f.write(("".join(random.choices(string.ascii_lowercase, k=random.randint(1, 50))) + "\n"))

with open('bigdata.txt', 'r')as fp:
    line = func(fp.readlines())
    while 1:
        try:
            print(line.__next__())
        except StopIteration:
            break


